package com.shiguo365.market.presenter.implement;

import android.app.Activity;
import android.app.Fragment;
import android.support.annotation.NonNull;
import android.util.Log;

import com.alibaba.fastjson.JSONObject;
import com.shiguo365.market.display.view.IIndexView;
import com.shiguo365.market.display.view.IUserCenterView;
import com.shiguo365.market.presenter.contract.IIndexPresenter;

import java.util.List;

import biz.yfsoft.api.ae.api.AEClient;
import biz.yfsoft.api.ae.api.AEParam;
import biz.yfsoft.api.ae.api.BaseAECallback;

/**
 * Created by caomenglong on 16/7/28.
 */
public class IndexPresenter implements IIndexPresenter {

    private static final String TAG = "IndexPresenter";
    private final Fragment mfragment;
    private final IIndexView mView;

    public IndexPresenter(@NonNull Fragment fragment, @NonNull IIndexView view) {
        this.mfragment = fragment;
        this.mView = view;
    }

    //获取首页商品数据
    @Override
    public void getIndexProList() {


        AEClient _client = new AEClient("shiguo.data.getHomeProList");
        _client.call(new AEParam(),new BaseAECallback() {

            @Override
            public void onSuccess(JSONObject a) {
                Log.e(TAG,"OKOK");
                mView.onGetIndexProListOk(a);
                //mainView.onRefreshProductListResultOk(tab, a);
            }

            @Override
            public void onError(String errno, String message) {
                super.onError(errno,message);
                Log.e(TAG,"onFailure ......." + errno);
            }

            @Override
            public void onFinally(String s) {
                mView.onGetIndexProListFinish();
            }
        });
    }

    //获取首页轮播图数据
    @Override
    public void getSlideBoxDataList() {
        Log.e(TAG,"读取轮播图");
        AEClient _client = new AEClient("shiguo.data.getHomeSlider");
        _client.call(new AEParam(),new BaseAECallback() {

            @Override
            public void onSuccess(List<JSONObject> jsonObjectList) {
                Log.e(TAG,jsonObjectList.toString());
                Log.e(TAG,"读取轮播图");
                mView.onGetHomeSlider(jsonObjectList);
                //mView.onGetHomeSlider(jsonObjectList);
                //mainView.onRefreshProductListResultOk(tab, a);
            }

            @Override
            public void onError(String errno, String message) {
                super.onError(errno,message);
                Log.e(TAG,"onFailure ......." + errno+message);
            }

            @Override
            public void onFinally(String s) {
                mView.onGetHomeSliderFinish();
            }
        });

    }
}
